home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE05 / EDSSPELL / EDSSPELL.ZIP / WSPELL.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1995-11-15  |  4.4 KB  |  161 lines

  1. unit WSpell;
  2.   {-spell dialog for EDSSpell component}
  3. interface
  4. uses
  5.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  6.   Forms, Dialogs, StdCtrls, Buttons, Menus,
  7.   ExtCtrls, EDSUtil, SpellInt;
  8.  
  9. type
  10.   Languages = (lgEnglish, lgSpanish);
  11. const
  12.   MaxBuffer       = 65535;
  13.   DictExt         : String[4] = '.DIC';
  14.   Dictionaries    : Array[Languages] of String[8]  =
  15.      ('English', 'Spanish');
  16.   EnglishStrings  : Array[Languages] of String[15] =
  17.      ('English', 'Spanish');
  18.   SpanishStrings  : Array[Languages] of String[15] =
  19.      ('InglΘs',  'Espa±ol');
  20. type
  21.   TBigBuffer      = Array[1..MaxBuffer] of Char;
  22.   PBigBuffer      = ^TBigBuffer;
  23.  
  24. type
  25.   Accents   = (acSpanish);
  26.   AccentSet = Set of Accents;
  27.   TSpellWin = class(TForm)
  28.     lblFound: TLabel;
  29.     lblNotFound: TLabel;
  30.     lblReplace: TLabel;
  31.     edtWord: TEnterEdit;
  32.     lblSuggestions: TLabel;
  33.     lstSuggest: TNewListBox;
  34.     btnReplace: TBitBtn;
  35.     btnSkip: TBitBtn;
  36.     btnSkipAll: TBitBtn;
  37.     btnSuggest: TBitBtn;
  38.     btnAdd: TBitBtn;
  39.     btnClose: TBitBtn;
  40.     pnlIcons: TPanel;
  41.     btnA: TSpeedButton;
  42.     btnE: TSpeedButton;
  43.     btnI: TSpeedButton;
  44.     btnO: TSpeedButton;
  45.     btnU: TSpeedButton;
  46.     btnN: TSpeedButton;
  47.     btnN2: TSpeedButton;
  48.     procedure edtWordExit(Sender: TObject);
  49.     procedure btnSuggestClick(Sender: TObject);
  50.     procedure lstSuggestChange(Sender: TObject);
  51.     procedure lstSuggestDblClick(Sender: TObject);
  52.     procedure btnAddClick(Sender: TObject);
  53.     procedure lblSuggestionsClick(Sender: TObject);
  54.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  55.       Shift: TShiftState);
  56.     procedure AccentClick(Sender: TObject);
  57.     procedure lstSuggestMouseDown(Sender: TObject; Button: TMouseButton;
  58.       Shift: TShiftState; X, Y: Integer);
  59.   private
  60.     { Private declarations }
  61.   public
  62.     { Public declarations }
  63.     NumToSuggest: byte;
  64.   end;
  65.  
  66. implementation
  67.  
  68. {$R *.DFM}
  69.  
  70. procedure TSpellWin.edtWordExit(Sender: TObject);
  71. var
  72.   ChkWord:  String;
  73. begin
  74.   lblNotFound.Caption := edtWord.Text;
  75.   if ActiveControl is TBitBtn then
  76.     exit;
  77.   ChkWord := edtWord.Text;
  78.   if dllInDictionary (ChkWord) then
  79.   begin
  80.     lblFound.Caption := 'Word found:';
  81.     ActiveControl  := btnReplace;
  82.   end {:} else
  83.   begin
  84.     lblFound.Caption := 'Not found:';
  85.     ActiveControl  := btnSuggest;
  86.   end;  { else }
  87. end;
  88.  
  89. procedure TSpellWin.btnSuggestClick(Sender: TObject);
  90. var
  91.   TempList:   TStringList;
  92. begin
  93.   TempList := dllSuggestWords (edtWord.Text, NumToSuggest);
  94.   lstSuggest.Items.Assign (TempList);
  95.   TempList.Free;
  96. end;
  97.  
  98. procedure TSpellWin.lstSuggestChange(Sender: TObject);
  99. begin
  100.   if lstSuggest.ItemIndex<>-1 then
  101.     edtWord.Text := lstSuggest.Items[lstSuggest.ItemIndex];
  102. end;
  103.  
  104. procedure TSpellWin.lstSuggestDblClick(Sender: TObject);
  105. begin
  106.   if lstSuggest.ItemIndex<>-1 then
  107.     edtWord.Text := lstSuggest.Items[lstSuggest.ItemIndex];
  108.   ModalResult := btnReplace.ModalResult;
  109. end;
  110.  
  111. procedure TSpellWin.btnAddClick(Sender: TObject);
  112. begin
  113.   if not dllInDictionary (lblNotFound.Caption) then
  114.   begin
  115.     if MessageDlg ('Add ' + lblNotFound.Caption + ' to Dictionary?',
  116.                    mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  117.       dllAddWord (lblNotFound.Caption);
  118.   end {:} else
  119.     MessageDlg (lblNotFound.Caption + ' already in Dictionary.',
  120.                 mtInformation, [mbOk], 0);
  121.   ActiveControl := edtWord;
  122. end;
  123.  
  124. procedure TSpellWin.lblSuggestionsClick(Sender: TObject);
  125. begin
  126.   Top := 15;
  127. end;
  128.  
  129. procedure TSpellWin.FormKeyDown(Sender: TObject; var Key: Word;
  130.   Shift: TShiftState);
  131. var
  132.   ClearKey: Boolean;
  133. begin
  134.   ClearKey := TRUE;
  135.   case Key of
  136.     Ord ('e'): if ssAlt in Shift then ActiveControl := lstSuggest;
  137.     Ord ('w'): if ssAlt in Shift then ActiveControl := edtWord;
  138.     else ClearKey := FALSE;
  139.   end;  { case }
  140.   if ClearKey then Key := 0;
  141. end;
  142.  
  143. procedure TSpellWin.AccentClick(Sender: TObject);
  144. begin
  145.   if Sender is TSpeedButton then
  146.     edtWord.SelText := TSpeedButton (Sender).Caption[1];
  147. end; { TSpellWin.AccentClick }
  148.  
  149. procedure TSpellWin.lstSuggestMouseDown(Sender: TObject;
  150.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  151. var
  152.   NewIndex: integer;
  153. begin
  154.   NewIndex := Y div lstSuggest.ItemHeight;
  155.   if NewIndex>lstSuggest.Items.Count-1 then
  156.     NewIndex := lstSuggest.Items.Count-1;
  157.   lstSuggest.ItemIndex := NewIndex;
  158. end;
  159.  
  160. end.  { WSpell }
  161.